<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>年度每月销售汇总查询</title>
		<%include("/common/include.html"){}%>
		<link rel="stylesheet" href="${cxt!}/sb/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
		<style type="text/css">
			.textbox{
				padding-right:0px;
				background:url("${cxt !}/sb/themes/insdep/images/combo_arrow.png") no-repeat scroll right center transparent;
			} 
		</style>
	</head>
	<body class="easyui-layout">
			<div data-options="region:'north',split: true,title:'快速查询'" style="height:200px;padding:10px;">
				<form id="yearSalesStaticFrom">
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">日期</label>
						<input id="yearSales_datetime" name="curDate" value='${date(),dateFormat="yyyy"}' class="easyui-numberspinner theme-textbox-radius" style="height:32px;width:212px;text-align:center"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">门店</label>
						<input id="organ" type="text" readonly style="width: 200px; height: 30px; padding-left: 10px;border-radius:3px" onclick="showMenu(); return false;" class="textbox" value="${curOrgan.name! }"/>
						<input name="organIds" id="organIds" type="hidden" value="${curOrgan.ids! }">
					</div>
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='searchFrom()' class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:212px">搜索</a>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='customerInfo_xls()' class="easyui-linkbutton" data-options="iconCls:'icon-pageexcel'" style="width:212px">导出</a>
					</div>
					</form>
	   	 	</div>
	   	 	<div data-options="region:'center',border: false" style="overflow-x:hidden;">
				<table id="yearSalesTable" style="width:100%;height:100%;">
					<thead frozen="true">
						<tr>
							<th data-options="field:'date',width:100,align:'center'">日期</th>
						</tr>
					</thead>
					<thead>
						<tr>
							<th data-options="field:'newpeoplenum',width:80,align:'center',rowspan:2" >新增人数</th>
							<th data-options="field:'newlcnum',width:80,align:'center',rowspan:2" >疗程数</th>
							<th data-options="field:'singlelc',width:100,align:'center',colspan:3" >单疗程</th>
							<th data-options="field:'normlc',width:100,align:'center',colspan:4" >标准疗程</th>
							<th data-options="field:'uplc',width:100,align:'center',colspan:3" >转疗程</th>
							<th data-options="field:'lctotalprice',width:50,align:'center',rowspan:2" >每月减重<br>金额合计</th>
							<%if(!isEmpty(products)){%>
								<%for(product in products){%>
									<th data-options="field:'${product.bh! }',width:80,align:'center',colspan:2">${product.name! }</th>
								<%}%>
							<%}%>
							<th data-options="field:'producttotalprice',width:50,align:'center',rowspan:2" >每月产品<br>金额合计</th>
							<th data-options="field:'sum',width:80,align:'center',rowspan:2" >每月总计<br>(减重+产品)</th>
						</tr>
						<tr>
							<th data-options="field:'singlelc_peoplenum',width:50,align:'center'" >人数</th>
							<th data-options="field:'singlelc_unitprice',width:50,align:'center'" >单价(元)</th>
							<th data-options="field:'singlelc_totalprice',width:50,align:'center'" >金额(元)</th>
							<th data-options="field:'normlc_peoplenum',width:50,align:'center'" >人数</th>
							<th data-options="field:'normlc_lcnum',width:50,align:'center'" >疗程数</th>
							<th data-options="field:'normlc_unitprice',width:50,align:'center'" >单价(元)</th>
							<th data-options="field:'normlc_totalprice',width:50,align:'center'" >金额(元)</th>
							<th data-options="field:'uplc_peoplenum',width:50,align:'center'" >人数</th>
							<th data-options="field:'uplc_lcnum',width:50,align:'center'" >疗程数</th>
							<th data-options="field:'uplc_totalprice',width:50,align:'center'" >金额(元)</th>
							<%if(!isEmpty(products)){%>
								<%for(product in products){%>
									<th data-options="field:'${product.bh! }_num',width:50,align:'center'">数量</th>
									<th data-options="field:'${product.bh! }_price',width:50,align:'center'">金额(元)</th>
								<%}%>
							<%}%>
							
						</tr>
					</thead>
				</table>
	    	</div>
	    	<div id="menuContent" class="menuContent" style="display: none; position: absolute;z-index: 10;">
				<ul id="organSelectTree" class="ztree" style="margin-top: 0;width: 200px;"></ul>
			</div>
		<script type="text/javascript">
			
			var $form = $('#yearSalesStaticFrom');
			function searchFrom(){
				initYearSalesTable();
			}
			function customerInfo_xls(){
	 			var yearSales_datetime = $("#yearSales_datetime").val();
	 			var organIds = $("#organIds").val();
	 			var url = "${cxt!}/yearSalesStatistic/excel?curDate=" + yearSales_datetime + "&organIds=" + organIds;
	 			window.location.href = url;
			}
			$(function() {
				var $form_div = $("#yearSalesStaticFrom div");
				winResize($form_div);
				$(window).resize(function(){//当调整浏览器窗口的大小时，发生 resize 事件
					winResize($form_div);
				});
			})
			function initTableTitle(){
				var name = $("#organ").val();
				return name;
			}
			function initYearSalesTable(){
				var name = initTableTitle();
				$('#yearSalesTable').datagrid({
					title:name,
					cls: "theme-datagrid",
					toolbar: '#tb',
					singleSelect: true,
					rownumbers: true, //显示序号
					url: "${cxt!}/yearSalesStatistic/view",
					queryParams: sy.serializeObject($form),
				    method: 'post',
					collapsible: true,
					onLoadSuccess:function(){
					},
					onClickRow:function(rowIndex,rowData){
					}
				});
			}
			//指定列求和
	        function compute(colName) {
	             var rows = $('#yearSalesTable').datagrid('getRows');
	             var total = 0;
	             for (var i = 0; i < rows.length; i++) {
	            	 if(typeof(rows[i][colName]) != 'undefined'){
	            		 total += parseFloat(rows[i][colName]);
	            	 }
	             }
	             if(total > 0){
	            	 return total;
	             }else{
	            	 return '';
	             }
	         }
		</script>
		<script type="text/javascript">
			var setting = {
				async : {
					enable : true,
					url : '${cxt!}/common/getOrgenTree',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					type : "post"
				},
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClick,
					onAsyncSuccess : organTreeOnAsyncSuccess
				}
			};
			var flag=0;//只初始化一次标识
			function organTreeOnAsyncSuccess(event, treeId, msg) {
				if(flag == 0){
					flag = 1;
					initYearSalesTable();
					
				}
			}
			function onClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("organSelectTree");
				var path = "";
				var sNodes = zTree.getSelectedNodes();
				if (sNodes.length > 0) {
					var node = sNodes[0].getPath();
					for(var i =0;i<node.length;i++){
						if(i == (node.length-1)){
							path += node[i].name;
						}else{
							path += node[i].name + "/";
						}
						
					}
				}
				var cityObj = $("#organ");
				cityObj.attr("value", path);
				$("#organIds").attr("value", treeNode.id);
				hideMenu();
			}
			function showMenu() {
				var cityObj = $("#organ");
				var cityOffset = $("#organ").offset();
				$("#menuContent").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
		
				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn"
						|| event.target.id == "menuContent" || $(event.target)
						.parents("#menuContent").length > 0)) {
					hideMenu();
				}
			}
			$.fn.zTree.init($("#organSelectTree"), setting);
		</script>
	</body>
</html>
